$(function () {


    $("#jqGrid").jqGrid({

        url: baseURL+"sdzblog/list",
        datatype: "json",
        colModel: [
            { label: '转出用户', name: 'payPhone', sortable:false, width: 80 },
			{ label: '货币类型',name: 'bid',sortable:false, width: 50,formatter:function (value,options,row) {
                if(value == "tbc_cny")
                    return "IMU";
                else if(value == "wbc_cny")
                    return "GET";
                else if(value == "bj_rmb")
                    return "易买宝";
                else
                    if(row.tid == 18 && value == 1)
                        return "静态奖";
                    else if(row.tid == 18 && value == 2)
                        return "动态奖";
                    else if(row.tid == 18 && value == 3)
                        return "服务奖";
                    return value;
            }},
            { label: '转入类型',name: 'tid',sortable:false, width: 50,formatter:function (value,options,row) {
                if(value == 1)
                    return '<span class="label label-danger">转出</span>' ;
                else if(value == 2)
                    return '<span class="label label-danger">转入</span>' ;
                else if(value == 3)
                    return '<span class="label label-danger">兑换</span>' ;
                else if(value == 4)
                    return '<span class="label label-danger">解冻</span>' ;
                else if(value == 5)
                    return '<span class="label label-danger">储存</span>' ;
                else if(value == 18)
                    return '<span class="label label-danger">理财益</span>' ;
                return "";
            }},
            { label: '交易数量',name: 'num',sortable:false, width: 80},
            { label: '账号数量',name: 'znum',sortable:false, width: 80},
            { label: '汇率',name: 'rmb',sortable:false, width: 80},
            { label: '目标用户',name: 'recPhone',sortable:false, width: 80},
            { label: '钱包地址',name: 'dizi',sortable:false, width: 80},
            { label: '交易时间',name: 'logtime',sortable:false, width: 80, formatter:"date", formatoptions: {srcformat:'U', newformat:'Y-m-d H:i:s'}},
        ],
        viewrecords: true,
        height: 385,
        rowNum: 20,
		rowList : [10,20,30,50,100,200],
        rownumbers: false,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.pageNum",
            total: "page.pages",
            records: "page.total",

        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order",

        },

        gridComplete:function(){
            //隐藏grid底部滚动条

            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });

        }
    });
    jQuery("#jqGrid").jqGrid('navGrid','#jqGrid',{edit:false,add:false,del:false});

    //过滤时间
    var rangetime = $('#filterTime').daterangepicker({
            autoApply:false,
            singleDatePicker:false,
            showDropdowns:true,         // 是否显示年月选择条件
            timePicker: true, 			// 是否显示小时和分钟选择条件
            timePickerIncrement: 10, 	// 时间的增量，单位为分钟
            timePicker24Hour : true,
            opens : 'left', //日期选择框的弹出位置
            startDate: moment().startOf('year'), //startDate和endDate 的值如果跟 ranges 的两个相同则自动选择ranges中的行. 这里选中了清空行
            endDate: moment().endOf('year'),
            ranges: {
                '今日': [moment().startOf('day'), moment().endOf('day')],
                '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
                '最近7日': [moment().subtract(6, 'days'), moment()],
                '最近30日': [moment().subtract(29, 'days'), moment()],
                '本月': [moment().startOf('month'), moment().endOf('month')],
                '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                '本年': [moment().startOf('year'), moment().endOf('year')],
                '去年': [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')]
            },
            locale : {
                //format: 'YYYY-MM-DD HH:mm:ss',
                format: 'YYYY-MM-DD HH:mm',
                separator : ' - ',
                customRangeLabel : '自定义',
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1,
                startDate: moment().startOf('day'),
                endDate: moment().endOf('day')
            }
        },
        function(start, end, label) // 格式化日期显示框
        {
            //选择时间 回调，暂时不做操作。。。
        });

    $('#filterTime').val('');
    setTimeout("$('#filterTime').val('')", 100);

    function fmtDate(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    };

});

var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            key: null
        },
        showList: true,
        title: null,
        dto: {}
    },
    methods: {
        query: function () {

            vm.reload();


        },
        trash: function () {
            $('#filterTime').val('');
        },

        reload: function (event) {
            vm.showList = true;
            var _postData = $("#jqGrid").jqGrid('getGridParam','postData');
            delete _postData['stime'];
            delete _postData['etime'];
            _postData['payPhone'] = $("#payPhone").val();
            _postData['recPhone'] = $("#recPhone").val();
            _postData['tid'] = $("#tradeType").val();
            _postData['bid'] = $("#moneyType").val();
            if((vtime = $.trim($('#filterTime').val())) != '')
            {
                if(vtime.indexOf(" - ") > -1)
                {
                    _postData['stime'] = getTime($.trim(vtime.split(" - ")[0]));
                    _postData['etime'] = getTime($.trim(vtime.split(" - ")[1]));
                }
                else
                {
                    _postData['stime'] = getTime(vtime);
                }
            }

            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                page:page
            }).trigger("reloadGrid");
        },
    }
});


